package com.zerowidth.moc.web.controller.serviceimpl;

import com.zerowidth.db.bean.MallBean;
import com.zerowidth.db.bean.OrderBean;
import com.zerowidth.db.bean.TeachBean;
import com.zerowidth.db.bean.YiYuanDuoBaoBean;
import com.zerowidth.db.op.*;
import com.zerowidth.moc.web.bean.YsePayBean;
import com.zerowidth.moc.web.controller.service.MallService;
import com.zerowidth.moc.web.resp.ResCode;
import com.zerowidth.moc.web.resp.ResultBean;
import com.zerowidth.moc.web.resp.helper.ResponseCreator;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class MallServiceImpl implements MallService {

    @Override
    public ResponseEntity<ResultBean<List<MallBean>>> getMallList() {

        List<MallBean> beanList = MallDB.getMallList();

        return ResponseCreator.creatOk(beanList, ResCode.CODE_OK, "获取商城物品成功");
    }

    @Override
    public ResponseEntity<ResultBean<YsePayBean>> createWXOrder(HttpServletRequest request, int mall_id, int mall_time_type, String price) {
        YsePayBean ysePayBean = new YsePayBean();

        float needPayPrice = Float.parseFloat(price);

        ysePayBean.qrcode_url = DataConfigDB.getValue("offLineQrCodeUrlWx");
        ysePayBean.money = String.format("%.2f", needPayPrice);
        ysePayBean.comment = "请在10分钟内完成以下所有操作\n" +
                "1、保存收款码到手机相册，支持截屏保存\n" +
                "2、用微信扫一扫相册中的收款码，输入正确的付款金额，完成支付\n\n" +
                "注意：\n" +
                "1、禁止随意修改金额，否则将导致支付无效，金额精确到小数点后两位" +
                "2、不需要担心软件怎么知道是哪个用户付的款，自有方法判断，请放心支付" +
                "3、如果微信提示支付风险，请无视并申请解除即可";

//        if (needToInsertDB) {
//            OrderBean orderBean = new OrderBean();
//            orderBean.vip_type = vipType;
//            orderBean.order_info = "";
//            orderBean.user_id = user_id;
//            orderBean.out_trade_no = "";
//            orderBean.amount = Float.parseFloat(ysePayBean.money);
//            orderBean.price = vipEnumBean.price;
//            orderBean.subject_value = vipEnumBean.vip_name + "订单";
//            orderBean.pay_success = false;
//            orderBean.order_type = OrderBean.TYPE_WXPAY;
//            orderBean.phone_number = "";
//            VipOrderDB.insert(orderBean);
//        }

        return ResponseCreator.creatOk(ysePayBean, ResCode.CODE_OK, "创建订单成功");
    }

}
